#ifndef CTRB_C
#define CTRB_C
#include "ctrb.h"

static int fp=0;
static Ctrb_State ctrb_state;

RETURN_ID Drv_Ctrb_Init()
{
	fp=open("/dev/HW_CTRB",0);
	if(!fp)
		return -CTRB_OPEN_FAILED;
	return -NO_ERROR;
}

RETURN_ID Drv_Ctrb_SendCmd(CTRB_CMD cmd)
{
	if(cmd>=CMD_COUNT)
		return -CTRB_INVALID_CMD;
	if(!fp)
		return -CTRB_NOT_OPEN;
	ioctl(fp,cmd);
	return -NO_ERROR;
}

RETURN_ID Drv_Ctrb_Uninit()
{
	if(fp)
		close(fp);
	fp=0;
	return -NO_ERROR;
}

Ctrb_State Drv_Ctrb_GetCtrb_State()
{
	read(fp,&ctrb_state,1);
	return ctrb_state;
}

#endif
